import 'package:ai/service/TextRecordService.dart';
import 'package:auto_route/annotations.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

import '../../config/Config.dart';
import '../../util/ToastUtils.dart';

@RoutePage()
class TextRecordDetail extends StatefulWidget {
  final int textTaskId;

  const TextRecordDetail({super.key, required this.textTaskId});

  @override
  State<TextRecordDetail> createState() => _TextRecordDetailState();
}

class _TextRecordDetailState extends State<TextRecordDetail> {
  final TextRecordService _textRecordService = TextRecordService();

  late String _content = "";

  @override
  void initState() {
    super.initState();
    _textRecordService.detail(widget.textTaskId).then((values) {
      setState(() {
        _content = values;
      });
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      appBar: AppBar(
        centerTitle: true,
        backgroundColor: Colors.white,
        title: const Text("历史记录"),
        leading: BackButton(
          onPressed: () {
            Navigator.of(context).pop();
          },
        ),
      ),
      body: ListView(
        children: [
          Padding(
            padding: const EdgeInsets.symmetric(horizontal: 16),
            child: Container(
              decoration: BoxDecoration(
                borderRadius: const BorderRadius.all(Radius.circular(8)),
                color: Config.colorF8,
              ),
              padding: const EdgeInsets.all(8),
              child: Text(_content),
            ),
          ),
        ],
      ),
      bottomNavigationBar: BottomAppBar(
        color: Colors.white,
        child: Expanded(
          child: FilledButton(
            style: ButtonStyle(
              backgroundColor: WidgetStateProperty.all(Config.primaryColor),
            ),
            onPressed: () {
              Clipboard.setData(
                ClipboardData(text: _content),
              );
              ToastUtils.success(context, "复制成功");
            },
            child: const Text("复制结果"),
          ),
        ),
      ),
    );
  }
}
